package org.whuims.core.dataprocessor;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by cheng on 2016/11/24.
 */
public class AllDocLister {
    private String filePath;
    private List<File> files = new ArrayList<File>();

    public AllDocLister(String filePath) {
        this.filePath = filePath;
    }

    public static void main(String[] args) {
        AllDocLister lister = new AllDocLister("src/main/webapp/resource/txt");
        List<File> files = lister.work();
        for (File file : files) {
            DocLoader loader = new DocLoader(file.getAbsolutePath());
            List<String> lines = loader.readLines();
            boolean ok = false;
            for (String line : lines) {
                if (line.trim().equals("1范围") || line.startsWith("1适用范围") || line.matches("\\s*1\\s*总\\s*则") || line.equals("1主题内容与适用范围")) {
                    ok = true;
                    break;
                }
            }
            if (!ok) {
                System.out.println(file.getName() + "\t" + ok);
            }
        }

    }

    public List<File> work() {
        crawl(new File(this.filePath));
        return files;
    }

    private void crawl(File targetFile) {
        if (targetFile.isFile()) {
            this.files.add(targetFile);
        } else if (targetFile.isDirectory()) {
            for (File f : targetFile.listFiles()) {
                crawl(f);
            }
        }
    }

}
